﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Controller;

public partial class Cliente : System.Web.UI.Page
{
    private DS_Lawyer.ForoDataTable dtForo
    {
        set { ViewState["dtForo"] = value; }
        get
        {
            object o = ViewState["dtForo"];
            if (o == null)
                return null;
            else
                return (DS_Lawyer.ForoDataTable)o;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            try
            {
                this.dtForo = cntrForo.Select();
                grdForo.DataSource = this.dtForo;
                grdForo.DataBind();
            }
            catch (Exception ex)
            {

                throw (new Exception(ex.Message));
            }
        }
    }
 
    protected void grdForo_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            
            cntrForo.Delete(this.dtForo[e.RowIndex].idForo);

            this.dtForo = cntrForo.Select();
            grdForo.DataSource = this.dtForo;
            grdForo.DataBind();
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));

        }
       
    }

    protected void grdForo_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            string idForo = this.dtForo[index].idForo;
            Response.Redirect("NewForo.aspx?IDForo=" + idForo);

        }

    }

    protected void btnPesquisar_Click(object sender, ImageClickEventArgs e)
    {
        string criterio = txtBuscaNome.Text.Trim() + "%";

        this.dtForo = cntrForo.SelectByNome(criterio);
        grdForo.DataSource = this.dtForo;
        grdForo.DataBind();
       
    }
    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {

    }
   
}
